from libavg import avg
from config import Config
from wheel import Wheel
from pinchableTrash import PinchableTrash
from dragableTrash import DragableTrash


class Board(avg.DivNode):

    __isLeft = True
    __wheel = None
    
    NO_COLLISION = 0
    WHEEL_COLLISION = 1
    GROUND_COLLISION = 2
    
    #hotfix
    __trashList = None
    
    # init method    
    def __init__(self, size, dad,pointsbar, isLeft):
        
        self.__isLeft = isLeft # IST ES DER LINKE SPIELR
        self.__trashList = [] # MUELLISTE
        posX = 0 
        
        if(not self.__isLeft):
            posX = Config.resX/2
        # set up div container
        avg.DivNode.__init__(self, size=(Config.boardHeight, Config.boardWidth), 
                                         crop = True, pos = (posX, 0), parent=dad)
        
        wheelPos = Config.leftWheel   
        self.__wheel = Wheel(wheelPos, self)

    

    def collided(self,trash):
        
        #SIZE
        trashSizeX = trash.getMediaSize()[0]
        trashSizeY = trash.getMediaSize()[1]
        
        
        trashRadius = trashSizeY/2
        trashMidPoint = trash.x + trashSizeX/2, trash.y + trashSizeY/2
        trashY = trash.y + trashSizeY
    
        #TESTING WHEEL COLLISION
        distance = self.__wheel.getWheelDistance(trashMidPoint[0], trashMidPoint[1])        
        if(distance <= self.__wheel.radius + trashRadius): 
            return Board.WHEEL_COLLISION
    
        #GROUND
        if(trashY >= Config.boardHeight):
            return Board.GROUND_COLLISION
        
        #NO COLLISION
        return Board.NO_COLLISION

    def addTrash(self, trash): # FUEGE OBJEKTE IN DIE MUELLLISTE VON BOARD
        self.__trashList.append(trash)
        
    def getTrashList(self): # GEBEN MUELLLISTE ZURUECK
        return self.__trashList
            
    def getWheel(self): # GEBE WINDRAD DES BOARDS ZURUECK
        return self.__wheel;